<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.util.*,SiTuQingYou.vo.*,SiTuQingYou.vo.*"
    pageEncoding="UTF-8"%>
    <%
   
     String path = request.getContextPath();
   
    %>
    
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="<%=path %>/houtai/js/jquery-3.3.1.min.js"></script>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <script type="text/javascript">
       $(document).ready(load);
    
       function load()
       {
   	    $("#addGuider").submit(sumb);
       }
       
       function sumb(){
    	   var fName = checkName();
    	   var fIdNumber = checkIdNumber();
    	   var fPhone = checkPhoneNumber();
    	   var fPrice = checkPrice();
    	   var fInformation = checkInformation();
    	   var fHead = checkHead();
    	   return fName&&fIdNumber&&fPhone&&fPrice&&fInformation&&fHead;
       }
        
        //姓名
        function checkName(){
        	var reg = /^[\u4e00-\u9fa5]{2,5}$/;
        	var theName = $("#nameid").val();
        	var flagName = reg.test(theName);
        	if(flagName)
        	{
        		$("#nameid").next().html("√");
        		$("#nameid").next().css("color","green");
        		return true;
        	}
        	else
        	{
        		$("#nameid").next().html("姓名需要是至少两位数汉字");
        		$("#nameid").next().css("color","red");
        		return false;
        	}
        }
        
        //身份证号
        function checkIdNumber(){
        	var reg = /^((\d{18})|(\d{17}X))$/;
        	var theIdNumber = $("#idnumberid").val();
        	var flagIdNumber = reg.test(theIdNumber);
        	if(flagIdNumber)
        	{
        		$("#idnumberid").next().html("√");
        		$("#idnumberid").next().css("color","green");
        		return true;
        	}
        	else
        	{
        		$("#idnumberid").next().html("身份证号不符合规范");
        		$("#idnumberid").next().css("color","red");
        		return false;
        	}
        }
        
        //手机号
        function checkPhoneNumber(){
        	var reg = /^(\d{11})$/;
        	var thePhone = $("#phoneid").val();
        	var flagPhone = reg.test(thePhone);
        	if(flagPhone)
        	{
        		$("#phoneid").next().html("√");
        		$("#phoneid").next().css("color","green");
        		return true;
        	}
        	else
        	{
        		$("#phoneid").next().html("手机号码固定11位数字");
        		$("#phoneid").next().css("color","red");
        		return false;
        	}
        }
        
        //导游价格
        function checkPrice(){
        	var reg = /^(((\d{2,})+(.\d{1,2}))|(\d{2,}))$/;
        	var thePrice = $("#priceid").val();
        	var flagPrice = reg.test(thePrice);
        	if(flagPrice)
        	{
        		$("#priceid").next().html("√");
        		$("#priceid").next().css("color","green");
        		return true;
        	}
        	else
        	{
        		$("#priceid").next().html("不符合格式规范");
        		$("#priceid").next().css("color","red");
        		return false;
        	}
        }
        
        //导游信息
        function checkInformation(){
        	
        	var theInformation = $("#informationid").val();
        	var flagInformation =theInformation.length>=10?true:false ;
        	if(flagInformation)
        	{
        		$("#informationid").next().html("√");
        		$("#informationid").next().css("color","green");
        		return true;
        	}
        	else
        	{
        		$("#informationid").next().html("请至少输入10个字符");
        		$("#informationid").next().css("color","red");
        		return false;
        	}
        }
        
        //导游头像
        function checkHead(){
        	
        	var theHead = $("#headid").val();
    
        	if(theHead==null||theHead=="")
        	{
        		$("#headid").next().html("请上传导游头像");
        		$("#headid").next().css("color","red");
        		return false;
        	}
        	else
        	{
        		return true;
        	}
        }
        
    </script>

    <form enctype="multipart/form-data" id="addGuider" method="post" action="/SiTuQingYou/GuiderServlet?method=addGuider">
        <%
          String t = request.getParameter("t");
        if("1".equals(t))
        {
        	out.println("<font style='color:green;font-size:24px;'>添加成功！</font>");
        }
        %>
        <div>导游姓名：<input type="text" id="nameid" name="guidername" maxlength="5" onblur="checkName()"><span></span></div>
        <div>性别：<input type="radio" name="sex" value="true" checked>男
                 <input type="radio" name="sex" value="false">女
        </div>
        <div>身份证号：<input type="text" id="idnumberid" name="idnumbername" maxlength="18" onblur="checkIdNumber()"><span></span></div>
        <div>手机号码：<input type="text" id="phoneid" name="phonename" maxlength="11" onblur="checkPhoneNumber()"><span></span></div>
        <div>导游费(每天)：<input type="text" id="priceid" name="pricename" maxlength="8" onblur="checkPrice()">元<span></span></div>
        <div>真实头像：<input type="file" name="headname" id="headid"><span></span></div>
        <div>导游信息：<textarea rows="8" cols="20" id="informationid" name="informationname" onblur="checkInformation()"></textarea><span></span></div>
        <div>导游所属城市:  
         <jsp:include page="../ScenehomeServlet">
			<jsp:param value="allcity" name="method"/>
			</jsp:include><select name="cityid">
     <%
     ArrayList<City> allcity = (ArrayList<City>)request.getAttribute("allcity");
								for(City city:allcity){
     %>	
      <option value="<%=city.getId() %>" >   <%=city.getCityname()%> </option><%} %>
    </select></div>
        <div><input type="submit" value="提交"></div>
    
    </form>


</body>
</html>